package com.work.straighttalk.ui;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;

import com.hyphenate.chat.EMClient;
import com.work.straighttalk.R;
import com.work.straighttalk.app.BaseActivity;
import com.work.straighttalk.bean.User;
import com.work.straighttalk.model.UserModel;

/**
 * 启动页面
 * Created by dllo on 16/3/1.
 */
public class SplashActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        //new Handler()和new Handler(Looper.getMainLooper())的区别
        //http://blog.csdn.net/thanklife/article/details/17006865
        Handler handler = new Handler(Looper.getMainLooper());
        //延时1秒 判断uesr是否为空来进入相应的activity
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                User user = UserModel.getInstance().getCurrentUser();
//                if (user != null && EMClient.getInstance().isLoggedInBefore()) {
//                    startActivity(MainActivity.class, null, true);
//                } else {
                    Log.d("SplashActivity", UserModel.getInstance().getCurrentUser().getUsername().toString());
                    Intent intent = new Intent(SplashActivity.this,LoginActivity.class);
                    startActivity(intent);
                    finish();
//                }
            }
        }, 2000);
    }
}